<template>
  <div class="source-card-wrapper" @click="gotoResource">
    <div class="source-intro">
      <div class="pub-info">
        <em class="pointableBlue" @click.stop="gotoAuthor">
          {{source.author_name}}
        </em> 
        <span style="color: var(--gray);padding: 0 5px;">|</span> 
        <em>
          {{formatDate}}
        </em>
        <span style="color: var(--gray);padding: 0 5px;">|</span> 
        <ul class="tags" :title="source.tag.join(',')">
          <li v-for="(tag, idx) of source.tag" :key="idx">
            {{tag}}
            <span> · </span>
          </li>
        </ul>
      </div>
      <h3 class="source-title">
        {{source.title}}
      </h3>
      <h3 class="source-abstract">
        {{source.digest}}
      </h3>
      <ul class="datas">
        <li v-for="(data, idx) in datas" :key="idx">
          <i class="iconfont" :class="data.iconClass"></i>
          <span>{{data.data}}</span>
        </li>
      </ul>
    </div>

    <div class="source-main" @click="gotoResource">
      <img :src="source.cover || fileIcon" alt="pdf">
      <a class="hover"></a>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      source: Object
    },
    data() {
      return {
        datas: [
          {
            iconClass: 'icon-eye',
            data: this.source.download_num
          },
          {
            iconClass: 'icon-like',
            data: this.source.like_num
          },
          {
            iconClass: 'icon-comment',
            data: this.source.comment_num
          },
          {
            iconClass: 'icon-collect',
            data: this.source.collect_num
          },
        ]
      }
    },
    computed: {
      fileIcon() {
        return this.$getFileIcon(this.source.source_name);
      },
      formatDate() {
        return this.source.publish_date 
        ? this.$dateUtils.format(this.source.publish_date, 'yyyy-MM-dd')
        : this.$dateUtils.format(Date.now(), 'yyyy-MM-dd');
      }
    },
    methods: {
      gotoResource() {
        this.$open(`/source/${this.source.id}`)
      },
      gotoAuthor() {
        this.$open(`/author/${this.source.author_id}/profile/source`)
      }
    },
    mounted () {
    },
  }
</script>

<style lang="less" scoped>
@h: var(--sourceCardHeight);
@w: var(--sourceCardWidth);

.source-card-wrapper {
  --scw: var(--sourceCardWidth);
  --sch: var(--sourceCardHeight);
  box-sizing: border-box;
  width: var(--scw);
  height: var(--sch);
  padding: calc(var(--sch) * 0.1) calc(var(--scw) * 0.04);

  &:hover {
    background-color: rgb(249, 249, 249);
    cursor: pointer;
  }

  .source-intro {
    float: left;
    width: 60%;
    text-align: left;
    pointer-events: none;

    .pub-info {
      font-size: calc(var(--sch) * 0.09);
      height: calc(var(--sch) * 0.17);
      line-height: calc(var(--sch) * 0.17);
      overflow: hidden;
      display: flex;
      justify-content: left;

      * {
        flex-shrink: 0;
      }

      .tags {
        li {
          float: left;
          font-size: calc(@h * 0.04);
          padding: 0 calc(@h * 0.03);
          color: var(--dark);
        }
      }
    }

    .source-title {
      font-size: calc(var(--sch) * 0.11);
      font-weight: bold;
      color: var(--dark);
      height: calc(var(--sch) * 0.22);
      line-height: calc(var(--sch) * 0.22);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-bottom: calc(var(--sch) * 0.05);
    }

    .source-abstract {
      font-size: calc(var(--sch) * 0.09);
      color: var(--dark);
      line-height: 1.5;
      display: -webkit-box;
      overflow: hidden;  
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }

    .datas {
      margin-top: calc(@h * 0.04);

      display: flex;
      justify-content: left;
      align-items: center;

      li{
        i, span {
          font-size: calc(@h * 0.02);
        }

        span {
          margin-left: calc(@h * 0.04);
        }

        &:not(:first-child) {
          margin-left: calc(@w * 0.05);
        }
      }
    }
  }

  .source-main {
    float: right;
    margin-right: 3%;
    height: 100%;
    padding: 0 5px;
    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      cursor: pointer;

      .hover {
        display: block;
      }
    }

    img {
      height: 90%;
    }

    .hover {
      display: none;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: 5px;
      background-color: var(--light);
    }
  }
}
</style>